/***************************************************************************************
* Copyright (c) 2014-2022 Zihao Yu, Nanjing University
*
* NEMU is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*          http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
*
* See the Mulan PSL v2 for more details.
***************************************************************************************/

#include <common.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "monitor/sdb/sdb.h"

void ftrace_end();
void init_monitor(int, char *[]);
void am_init_monitor();
void engine_start();
void exit_sim();
int is_exit_status_bad();
void bp_clear();

int npc_main(int argc, char *argv[]) {
  /* Initialize the monitor. */
#ifdef CONFIG_TARGET_AM
  am_init_monitor();
#else
  init_monitor(argc, argv);
#endif

  //-----------------------------------------
  // 测试
  /*uint32_t result;*/
  /*char exp[1000];*/
  /*char buf[1000] = {'\0'};*/
  
  /*FILE *fp = fopen("/home/ubuntu20/Desktop/ysyx-workbench/nemu/tools/gen-expr/input", "r");*/
  
  /*if (fp == NULL) assert(0);*/
  
  /*int flag = 1;*/
  
  /*int count = 1;*/
  /*while (fgets(buf, 1000, fp) != NULL) {*/
    /*sscanf(buf, "%d %s", &result, exp);*/
  
    /*bool success = true;*/
    /*printf("------%d\n", count++);*/
    /*if (expr(exp, &success) != result) {*/
      /*flag = 0;*/
    /*}*/
    /*else {*/
      /*printf("result: %u\n", result);*/
    /*}*/
  /*}*/
  
  /*if (flag == 0) printf("SUCCESS!!!\n");*/
  /*else printf("FAIL!!!\n");*/
  
  /*fclose(fp);*/
  //-----------------------------------------

  /* Start engine. */
  engine_start();

#ifdef CONFIG_FTRACE
  ftrace_end();
#endif

  exit_sim();
  bp_clear();

  return is_exit_status_bad();
}
